package com.example.medical.controller;

import com.example.medical.domain.Shop;
import com.example.medical.domain.User;
import com.example.medical.service.UserService;
import com.example.medical.util.AjaxResuit;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@Api(tags = "用户管理（0525王婕）")
public class UserController {
    @Autowired
    UserService service;
    @GetMapping("/getUserListAll")
    @ApiOperation(value = "获取用户列表")
    public AjaxResuit getUserListAll() {
        System.out.println(service.selectAll());
        return AjaxResuit.success(service.selectAll());
    }
    @GetMapping("/getUserById")
    @ApiOperation(value = "根据id查询用户信息")
    public AjaxResuit getUserById(int id) {
        System.out.println(service.selectById(id));
        return AjaxResuit.success(service.selectById(id));
    }
    @PostMapping("/addUser")
    @ApiOperation(value = "新增用户")
    public AjaxResuit addUser(@RequestBody User user) {
        return AjaxResuit.success(service.SaveUser(user));
    }

    @PutMapping("/updateUser")
    @ApiOperation(value = "更新用户信息")
    public AjaxResuit updateShop(@RequestBody User user) {
        int result = service.UpdateUser(user);
        if (result > 0) {
            return AjaxResuit.success("用户信息更新成功");
        } else {
            return AjaxResuit.error("用户信息更新失败");
        }
    }

    @DeleteMapping("/deleteUser")
    @ApiOperation(value = "删除用户")
    public AjaxResuit deleteUser(int id) {
        int result = service.DeleteUser(id);
        if (result > 0) {
            return AjaxResuit.success("用户删除成功");
        } else {
            return AjaxResuit.error("用户删除失败");
        }
    }
    @PostMapping("/UserLogin")
    @ApiOperation(value = "用户登录")
    public AjaxResuit UserLogin(User user) {
        return AjaxResuit.success(service.checkUser(user));
    }
}
